var GameData = require('../../module/GameData')();

cc.Class({
    extends: cc.Component,

    properties: {
        text: cc.Label
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.is_select = false;
    },
    init(data) {
        this.text.string = data.text;
        this.node.getChildByName("clicktext").getComponent(cc.Label).string = data.text;
        this.id = data.id;
        if (data.id === 0) {
            this.is_select = true;
            this.select_id = 0;
            this.changeState(1);
        } else {
            this.changeState(0);
        }
    },

    start() {

    },
    callfun() {
        // if(this.id!==this.select_id){
        this.restchange();
        this.changeState(1);
        console.log(GameData.shop.shop_goods_list.content.position);
        let len=0;
        for (var a=0;a<this.id;a++){
            len-=GameData.shop.shop_goods_list.content.children[a].width;
        }
        let Arr=[-568,-850,-1320,-1920,-2540,-3000,-3850];
        //
        GameData.shop.shop_goods_list.content.setPosition(cc.v2(Arr[this.id], 0));
        console.log(-568+len/2)
        // }
    },
    restchange() {
        for (var a = 0; a < GameData.shop.down_itemArr.length; a++) {
            GameData.shop.down_itemArr[a].getChildByName("text").active = true;
            GameData.shop.down_itemArr[a].getChildByName("clicktext").active = false;
        }
    },
    changeState(num) {
        if (num === 1) {/*选中状态*/
            this.node.getChildByName("text").active = false;
            this.node.getChildByName("clicktext").active = true;
        } else {/*未选中状态*/
            this.node.getChildByName("text").active = true;
            this.node.getChildByName("clicktext").active = false;
        }
    },
    // update (dt) {},
});
